package auctionhausen



import grails.test.mixin.*
import org.junit.*

@TestFor(ListingService)
@Mock([Customer, Listing])
class ListingServiceTests {

	void testCreateListing() {
		def listingsCount = 0;
		Listing.metaClass.static.count = { return listingsCount }
		Listing.metaClass.save = { Map m ->
			listingsCount += 1
			return new Listing()
		}

		def params = [:]
		def listing = service.createListing(params)
		assert Listing.count() == 1
	}

	void testCreateListing_FailsForInvalidParams() {
		def listingsCount = 0;
		Listing.metaClass.static.count = { return listingsCount }
		Listing.metaClass.save = { Map m -> return null }

		def params = [:]
		def listing = service.createListing(params)
		assert Listing.count() == 0
	}
}
